package com.heima.home.dto;

import com.heima.home.entity.Users;
import lombok.Data;

@Data
public class UserInfoResponse {
    private Integer id;
    private String username;
    private String email;
    private String phone;
    private String realName;
    private String idCard;
    private String avatar;
    private Integer gender;
    private String birthday;
    private Integer userType;
    private Integer totalOrders;
    private Integer totalReviews;
    private Integer totalFavorites;

    public static UserInfoResponse fromUser(Users user) {
        if (user == null) return null;
        UserInfoResponse response = new UserInfoResponse();
        response.setId(user.getId());
        response.setUsername(user.getUsername());
        response.setEmail(user.getEmail());
        response.setPhone(user.getPhone());
        response.setRealName(user.getRealName());
        response.setIdCard(user.getIdCard());
        response.setAvatar(user.getAvatar());
        response.setGender(user.getGender());
        // 转换 Date 为 String
        if (user.getBirthday() != null) {
            response.setBirthday(new java.text.SimpleDateFormat("yyyy-MM-dd").format(user.getBirthday()));
        }
        response.setUserType(user.getUserType());
        return response;
    }
}